use "D:\Nanjing\2019\pollution2\submission\files for submission\data\tables_mechanism", clear
replace indc_e=0 if indc_e==.
replace indc_abt=0 if indc_abt==.
*replace cic_so2=0 if cic_so2==.
replace dust_new1=dust_new2 if dust_new1!=.
replace exp_e=exp_dummy2*indc_e
replace exp_abt=exp_dummy2*indc_abt
replace exp_index1=exp_dummy2*cic_so2

capture drop IV1 
capture drop IV2
capture drop  IV3 
capture drop IV4

gen IV1=exp_dummy_lag *RD_d
gen IV2=exp_dummy_lag *coal_share_lag
gen IV3=exp_dummy_lag *lnv_lag
gen IV4=exp_dummy_lag *dirty_dust
gen IV5=exp_dummy_lag *indc_e
gen IV6=exp_dummy_lag *indc_abt
gen IV7=exp_dummy_lag*cic_so2

rename exp_dummy2 Export
rename so2_new1 Abatement_so2
rename dust_new1 Abatement_dust
rename lnv_lag vintage
rename exp_v exp_vintage
rename tfp_acf_new Productivity
rename coal_share_lag NRG
rename exp_coal exp_NRG
rename dirty_so2 Mix
rename exp_so2 exp_mix
rename RD_d RD
rename lnkl_lag lnKL
rename lntariff Tariff
rename treatment_tfp tariff_prod
rename treatment_so2 ventilation_prod
rename cic_so2 Demand
*-----------------------------------------
* 25.1 RD IV: columns 2-3 of Table A25
*----------------------------------------
ivreghdfe lndust  (Export Abatement_dust =tariff_prod ventilation_prod  ventilation ) RD  Productivity Tariff lnKL  lndust_ini  , a(cic prov year ownership) cluster(prov_c)
ivreghdfe lndust  (Export Abatement_dust exp_rd =tariff_prod ventilation_prod  ventilation exp_dummy_lag  IV1) RD  Productivity Tariff lnKL  lndust_ini, a(cic  prov year ownership) cluster(prov_c)
*******************************************************


 /*
* compute R2
predict y_hat, xb
egen y_bar=mean(lndust)

gen diff1=(y_hat-y_bar)^2
egen SSR=sum(diff1)

gen diff2=(lndust-y_bar)^2
egen SST=sum(diff2)

gen R2=SSR/SST 
sum R2
*/
*-------------------------------------------------  
* 25.2 capital vintage IV:  columns 4-5 of Table 25
*----------------------------------------------------
ivreghdfe lndust  (Export Abatement_dust =tariff_prod ventilation_prod  ventilation) vintage Productivity Tariff lnKL  lndust_ini  , a(cic  prov year ownership) cluster(prov_c)

ivreghdfe lndust  (Export Abatement_dust exp_vintage=tariff_prod ventilation_prod  ventilation exp_dummy_lag IV3) ///
vintage Productivity Tariff lnKL  lndust_ini, a(cic  prov year ownership) cluster(prov_c)

**************************************************************

*-------------------------------------------------
*25.3 energy share IV:  columns 6-7 of Table 25
*------------------------------------------------
ivreghdfe lndust  (Export Abatement_dust =tariff_prod ventilation_prod  ventilation ) NRG Productivity Tariff lnKL  lndust_ini , a(cic  prov year ownership) cluster(prov_c)

ivreghdfe lndust  (Export Abatement_dust exp_NRG=tariff_prod ventilation_prod  ventilation exp_dummy_lag IV2)  NRG Productivity Tariff lnKL  lndust_ini, a(cic  prov year ownership) cluster(prov_c)

***************************************************************



*--------------------------------------------------------
* 25.4 Energy import share: columns 8-9 of Table 25
*-------------------------------------------------------
ivreghdfe lndust  (Export Abatement_dust =tariff_prod ventilation_prod  ventilation ) indc_e  Productivity Tariff lnKL  lndust_ini  , a(cic prov year ownership) cluster(prov_c)

ivreghdfe lndust  (Export Abatement_dust exp_e =tariff_prod ventilation_prod  ventilation  IV5) indc_e  Productivity Tariff lnKL  lndust_ini, a(cic  prov year ownership) cluster(prov_c)
*********************************************************************************************************************************************************************************************************

*----------------------------------------------------
*25.5 Import abatement IV:  columns 10-11 of Table 25
*----------------------------------------------------
ivreghdfe lndust  (Export Abatement_dust =tariff_prod ventilation_prod  ventilation ) indc_abt Productivity Tariff lnKL  lndust_ini , a(cic  prov year ownership) cluster(prov_c)

ivreghdfe lndust  (Export Abatement_dust exp_abt= tariff_prod ventilation_prod  ventilation exp_dummy_lag  IV6)  indc_abt Productivity Tariff lnKL  lndust_ini, a(cic  prov year ownership) cluster(prov_c)




***************************************************************************************************************

*---------------------------------------------
*25.6 product-mix IV: columns 12-13 of Table 25
*---------------------------------------------
ivreghdfe lndust  (Export Abatement_dust =tariff_prod ventilation_prod  ventilation) Mix Productivity Tariff lnKL  lndust_ini  , a(cic  prov year ownership) cluster(prov_c)

ivreghdfe lndust  (Export Abatement_dust exp_mix=tariff_prod ventilation_prod  ventilation exp_dummy_lag IV4) Mix Productivity Tariff lnKL  lndust_ini  , a(cic  prov year ownership) cluster(prov_c)

*************************************************************




*----------------------------------------------------------------
use  "D:\Nanjing\2019\pollution2\submission\files for submission\data\environ_index", clear
*-----------------------------------------------------------

* gen IVs for interaction term
capture drop IV1 
capture drop IV2
capture drop  IV3 
capture drop IV4


gen IV1=exp_dummy_lag *cic_so2
gen IV2=exp_dummy_lag *cic_co2


rename exp_dummy2 Export
rename so2_new1 Abatement_so2
rename dust_new1 Abatement_dust
rename lnv_lag vintage
rename exp_v exp_vintage
rename tfp_acf_new Productivity
rename coal_share_lag NRG
rename exp_coal exp_NRG
rename dirty_so2 Mix
rename exp_so2 exp_mix
rename RD_d RD
rename lnkl_lag lnKL
rename lntariff Tariff
rename treatment_tfp tariff_prod
rename treatment_so2 ventilation_prod

rename cic_so2 Demand

*---------------------------------------------
*25.7 RD IV: columns 14-15 of Table 25
*---------------------------------------------
ivreghdfe lndust (Export Abatement_dust =tariff_prod ventilation_prod  ventilation ) Demand Productivity Tariff lnKL  lndust_ini  , a(cic prov year ownership) cluster(prov_c)

ivreghdfe lndust  (Export Abatement_dust exp_index1 =tariff_prod ventilation_prod  ventilation   IV1) Demand Productivity Tariff lnKL  lndust_ini, a(cic  prov year ownership) cluster(prov_c)
*******************************************************





****************************************************************************

use "D:\Nanjing\2019\pollution2\submission\files for submission\data\tables_mechanism", clear
replace indc_e=0 if indc_e==.
replace indc_abt=0 if indc_abt==.
*replace cic_so2=0 if cic_so2==.
replace dust_new1=dust_new2 if dust_new1!=.
replace exp_e=exp_dummy2*indc_e
replace exp_abt=exp_dummy2*indc_abt
replace exp_index1=exp_dummy2*cic_so2

capture drop IV1 
capture drop IV2
capture drop  IV3 
capture drop IV4

gen IV1=exp_dummy_lag *RD_d
gen IV2=exp_dummy_lag *coal_share_lag
gen IV3=exp_dummy_lag *lnv_lag
gen IV4=exp_dummy_lag *dirty_dust
gen IV5=exp_dummy_lag *indc_e
gen IV6=exp_dummy_lag *indc_abt
gen IV7=exp_dummy_lag*cic_so2

rename exp_dummy2 Export
rename so2_new1 Abatement_so2
rename dust_new1 Abatement_dust
rename lnv_lag vintage
rename exp_v exp_vintage
rename tfp_acf_new Productivity
rename coal_share_lag NRG
rename exp_coal exp_NRG
rename dirty_so2 Mix
rename exp_so2 exp_mix
rename RD_d RD
rename lnkl_lag lnKL
rename lntariff Tariff
rename treatment_tfp tariff_prod
rename treatment_so2 ventilation_prod
rename cic_so2 Demand
*---------------------------------------------
*25.8 RD IV: columns 14-15 of Table 25
*---------------------------------------------
ivreghdfe lndust  (Export Abatement_dust=tariff_prod ventilation_prod  ventilation ) RD NRG vintage Mix  indc_e  indc_abt Demand Productivity Tariff lnKL  lndust_ini , a(cic prov year ownership)  cluster(prov_c)


ivreghdfe lndust  (Export Abatement_dust exp_rd exp_NRG exp_vintage exp_mix  exp_e exp_abt exp_index1=tariff_prod ventilation_prod  ventilation exp_dummy_lag IV1 IV2 IV3 IV4 IV5 IV6 IV7)  RD NRG vintage Mix indc_e  indc_abt Demand  Productivity Tariff lnKL  lndust_ini  , a(cic prov year ownership) cluster(prov_c)




